

$(document).ready(function() {
	
	//var url = basePath+"/dic/addDic";
	var url = basePath+"/role/addRole";
	
	if($("#roleId").val() != "" || $("#roleId").val() == null){
		//url = basePath+"/dic/editDic";
		url = basePath+"/role/editRole";
	}
	
	
	$("#subBtn").on("click",function(){
		var ids = "";
		//获取被选中的数据Id
		$(".formControls :checkbox").each(function(){
			
			if($(this).is(':checked')){
				ids +=$(this).val()+",";
			}
			
		});
		
		if(ids != ""){
			$.ajax({
				type:"post",
				url:basePath+"/role/editRolePer",
				data:{"perIds":ids,"roleId":$("#roleId").val()},
				async:false,
				success:function(data){
					if(data.code == "-3"){
		        		 layer.msg("管理员登录超时，请重新登录",{time:1000});
		        		 setTimeout(function(){
		        			 window.parent.parent.location.href=basePath+"/login";
			        	 },2000)
			        	 return false;
		        	}
					if(data.code=="0"){
						layer.msg(data.msg,{icon:1,time:1000});
					}else{
						alert('error');
					}
				}
			});
		}else{
			layer.msg('请更改数据',{icon:1,time:1000});
		}
	});
	
/*	$(".form-horizontal").validate({
		submitHandler:function(form){
			$(form).ajaxSubmit({
		        type:"post",
		        url:url,
		        async:false,
		        //beforeSubmit: showRequest,
		        success: function(data){
		        	 layer.msg(data.msg,{time:1000});
		        	 setTimeout(function(){
		        		 parent.location.reload();
		        		 var index = parent.layer.getFrameIndex(window.name);
			        	 parent.layer.close(index);
		        	 },1000)
		        	 
		        	
		        }
		      });
		}
	});*/
	
});
